<template>
  <div class="categories-container">
    <h2 class="section-title">文章分类</h2>
    <div v-for="category in categories" :key="category" @click="viewArticlesByCategory(category)">
      <p>{{ category }}</p>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      categories: []
    };
  },
  async mounted() {
    try {
      const response = await axios.get('/article/categories');
      this.categories = response.data.data;
    } catch (error) {
      console.error('获取文章分类出错', error);
    }
  },
  methods: {
    viewArticlesByCategory(category) {
      this.$router.push(`/articlesByCategory/${category}`);
    }
  }
};
</script>

<style scoped>
.categories-container {
  padding: 30px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.08);
}
</style>